package cn.leelei.hibernate.utils;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;
/**
 * 自定义主键生成策略
 * 用时间详细来生成订单编号
 * @author Nike
 *
 */
public class CustomStrategy implements IdentifierGenerator{
	private static final DateFormat Format = new SimpleDateFormat("yyyyMMddHHmmssss");
	@Override
	public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
		//当前时间
		Date date = new Date();
		//得到时间对象
		String time = Format.format(date);
		return time;
	}

}
